package com.example.controller;

import com.example.pojo.Maintain;
import com.example.pojo.Result;
import com.example.service.MaintainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RequestMapping("/serviceapartment")
@RestController
public class MaintainController {
    @Autowired
    private MaintainService maintainService;

    @Autowired
    private HttpServletRequest request;

    //租客上传维修房
    @PostMapping
    public Result addServiceApartment(@RequestBody Maintain maintain){
        /*if(maintain.getDamage()==null || maintain.getDamage()==""){
            return Result.error("请输入损坏需要维修位置");
        }
        if(maintain.getDamageType()==null){
            return Result.error("请选择损坏方式");
        }
       *//* if(maintain.getQDate()==null){
            return Result.error("请输入希望维修日期");
        }*//*
        if(maintain.getTnumber()==null || maintain.getTnumber()==""){
            return Result.error("请输入联系电话");
        }
        if(maintain.getIdA()==null){
            return Result.error("请选择需要维修的房源");
        }*/
        log.info("{}",maintain.getIdA());
        maintainService.addServiceApartment(maintain,request);
        return Result.success();
    }

    //租客显示维修房源
    @GetMapping("/tenant")
    public Result getServiceApartmentZK(){
        List<Maintain> list=maintainService.getServiceApartmentZK(request);
        return Result.success(list);
    }


    //房东显示维修房源
    @GetMapping("/landlady")
    public Result getServiceApartmentFD(String name,Integer sfpd){
        log.info("{}",sfpd);
        List<Maintain> list=maintainService.getServiceApartmentFD(name,sfpd,request);
        return Result.success(list);
    }

    //房东派遣维修人员
    @PutMapping
    public Result setServiceman(@RequestBody Maintain maintain){
        log.info("{}",maintain.getId());
        maintainService.setServiceman(maintain,request);
        return Result.success();
    }

    //房东点击维修完成
    @PutMapping("/{id}")
    public Result setRepair(@PathVariable Integer id){
        maintainService.setRepair(id,request);
        return Result.success();
    }
}
